package com.yl.web.controller.api;

import com.yl.common.core.domain.AjaxResult;
import com.yl.common.core.page.TableDataInfo;
import com.yl.domain.UserDO;
import com.yl.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户信息
 *
 * @author : y
 * @date : 2024/6/4 9:20
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserService userService;

    /**
     * 获取当前用户信息
     *
     * @author : y
     * @date :  2024/6/3 15:55
     **/
    @RequestMapping("/getByToken")
    @ResponseBody
    public AjaxResult getByToken() {
        log.info("获取当前用户信息---start------参数：{}");
        UserDO userDO = userService.getByToken();
        if (userDO != null) {
            return AjaxResult.success(userDO);
        } else {
            return AjaxResult.error("未查询到个人信息");
        }
    }

    /**
     * 注册账号
     *
     * @author : y
     * @date :  2024/6/3 15:55
     **/
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestBody UserDO userDO) {
        log.info("注册账号---start------参数：{}", userDO);
        return userService.save(userDO);
    }

    /**
     * 账号列表
     * @author : y
     * @date :  2024/6/3 15:55
     **/
    @RequestMapping("/findPage")
    @ResponseBody
    public TableDataInfo findPage(@RequestBody UserDO userDO) {
        log.info("账号列表---start------参数：{}", userDO);
        return userService.findPage(userDO);
    }






}
